/*
	Name:直径
	Author: There,hello 
	Date: 12-10-19 15:23
	Description: Luogu P3304
	Algorithm: 树的直径 
*/
#include<bits/stdc++.h>
using namespace std;
int n,head[202020],tail,ans[202020],ans_len,l_pos,r_pos,ll,rr,d[202020],beginn,endd;
long long len_max,sum[202020];
struct dd{
    int ne,to,w;
}side[402020];
inline void add(int x,int y,int z){
    side[++tail].ne=head[x];
    side[tail].to=y;
    side[tail].w=z;
    head[x]=tail;
}
void dfs(int t,int fa,int deep,long long ww,int &pos1){
	bool f=1;
	for(int i=head[t];i;i=side[i].ne){
        if(fa!=side[i].to){
        	f=0;
            dfs(side[i].to,t,deep+1,ww+side[i].w,pos1);
        }
    }
	if(f&&len_max<ww){
		len_max=ww;
		ans_len=deep;
		pos1=t;
    }
}
bool dfs4(int t,int fa,int deep,long long ww,int endd){
	sum[deep]=ww;
	ans[deep]=t;
	if(t==endd){
		return 1;
	}
	for(int i=head[t];i;i=side[i].ne){
        if(fa!=side[i].to){
            if(dfs4(side[i].to,t,deep+1,ww+side[i].w,endd))
            break;
        }
    }
    return 0;
}
void getmax(){
    dfs((rand()%n)+1,0,0,0,beginn);
    dfs(beginn,0,0,0,endd);
}
void dfs2(int t,int fa,long long ww,long long &w){
	w=max(w,ww);
    for(int i=head[t];i;i=side[i].ne){
        if(fa!=side[i].to&&side[i].to!=ans[r_pos]){
            dfs2(side[i].to,t,ww+side[i].w,w);
        }
    }
}
void dfs3(int t,int fa,long long ww,int &p,long long w){
	for(int i=head[t];i;i=side[i].ne){
		if(side[i].to!=fa){
			dfs3(side[i].to,t,ww+side[i].w,p,w);
			int noww=d[side[i].to]+side[i].w;
			if(noww>d[t]){
				d[t]=noww;
			}
			else if(noww==d[t]&&d[t]+ww==w){
					p=t;break;
			}
		}
	}
} 
int find_zhongdian(){
	int pos;
	long long minn=0x7fffffffffffffff;
	for(int i=1;i<=ans_len;++i){
		if(abs(sum[ans_len]-sum[i]*2)<minn){
			pos=ans[i];
			l_pos=i-1; 
			r_pos=i+1;
			minn=abs(sum[ans_len]-sum[i]*2);
		}
	}
	return pos;
}
int main(){
    srand(time(NULL));
    scanf("%d",&n);
    for(int i=1,x,y,z;i<n;++i){
        scanf("%d%d%d",&x,&y,&z);
        add(x,y,z);
        add(y,x,z);
    }
    getmax();
    dfs4(beginn,0,0,0,endd);
    cout<<beginn<<" "<<endd<<endl;
    for(int i=0;i<=ans_len;++i)
    cout<<ans[i]<<" ";
    printf("%lld\n",len_max);
	int zhongdian=find_zhongdian();
	long long ldep=sum[l_pos],ldep2=sum[l_pos+1],rdep=sum[ans_len]-sum[r_pos],rdep2=sum[ans_len]-sum[r_pos-1];
	ll=ans[0];
	if(ldep2<rdep2){
		swap(rdep,ldep);
		swap(ldep2,rdep2);
		swap(l_pos,r_pos);
		ll=ans[ans_len];
	}
	dfs3(ans[l_pos],zhongdian,0,ll,ldep);
	long long dis_mx=0;
	dfs2(zhongdian,ans[l_pos],0,dis_mx);
	if(dis_mx==rdep2){
		if(ldep2==rdep2){
			putchar('0');
			return 0;
		}
		int pos1,pos2;
		for(int i=0;i<=ans_len;++i)
		if(ll==ans[i]){
			pos1=i;break;
		}
		for(int i=0;i<=ans_len;++i)
		if(zhongdian==ans[i]){
			pos2=i;break;
		}
		printf("%d",abs(pos2-pos1));
		return 0;
	}
	dfs3(ans[r_pos],zhongdian,0,rr,rdep);
	int pos1,pos2;
	for(int i=0;i<=ans_len;++i)
	if(ll==ans[i]){
		pos1=i;break;
	}
	for(int i=0;i<=ans_len;++i)
	if(rr==ans[i]){
		pos2=i;break;
	}
	printf("%d",abs(pos2-pos1));
	return 0;
} 
